import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../../providers/order_provider.dart';

class OrderRemark extends StatefulWidget {
  const OrderRemark({Key? key}) : super(key: key);

  @override
  _OrderRemarkState createState() => _OrderRemarkState();
}

class _OrderRemarkState extends State<OrderRemark> {
  String remark = "";

  @override
  Widget build(BuildContext context) {
    remark = Provider.of<OrderProvider>(context).remark;

    return Container(
      margin: const EdgeInsets.all(10),
      padding: const EdgeInsets.all(10),
      decoration: BoxDecoration(
        border: Border.all(width: 1, color: Colors.grey.shade300)
      ),
      child: TextField(
        autofocus: false,
        keyboardType: TextInputType.text,
        maxLines: 5,
        textAlign: TextAlign.left,
        textDirection: TextDirection.ltr,
        decoration: const InputDecoration(
          isCollapsed: true, // 必须设置为 true，否则默认为最小高度
          border: InputBorder.none,
          hintText: "订单备注",
          hintStyle: TextStyle(
            fontSize: 14
          )
        ),
        onChanged: (value) {
          // 将订单备注，保存到状态中
          Provider.of<OrderProvider>(context, listen: false).setRemark(value.toString());

          setState(() {
            remark = value;
          });
        }
      ),
    );
  }
}